package org.example.test;

/**
 * @author: lynn
 * @Descript: 打印一个字符串的所有全排列结果
 * @date: 2021/3/4 22:34
 * @version: 1.0
 */
public class PrintSubChars {
    public static void main(String[] args) {
        printAllPermutations("abc".toCharArray(), 0);
    }

    public static void printAllPermutations(char[] chs,int index) {
        //base case
        if(index == chs.length-1) {
            System.out.println(chs);
            return;
        }
        for (int j = index; j < chs.length; j++) {
            swap(chs,index,j);
            printAllPermutations(chs, index+1);
        }
    }

    public static void swap(char[] chs,int i,int j) {
        char temp = chs[i];
        chs[i] = chs[j];
        chs[j] = temp;
    }
}

